const ul = document.querySelector(".scroll-container");
const ulStyle = getComputedStyle(ul);

function clone() {
    const firstElement = document.querySelector("ul li");
    const newEle = firstElement.cloneNode(true);
    ul.appendChild(newEle);
}
clone();

const list = document.querySelectorAll("li");
let itemHeight = list[0].offsetHeight;
let currentIndex = 0;
function moveTo() {
    let from = itemHeight * currentIndex;
    currentIndex++;
    let to = itemHeight * currentIndex;
    let totalDuration = 300;
    let duration = 10;
    let times = totalDuration / duration;
    let dis = (to - from) / times;
    let timerId = setInterval(() => {
        from += dis;
        if (from >= to) {
            clearInterval(timerId);
            if (currentIndex === list.length - 1) {
                from = 0;
                currentIndex = 0;
            }
        }
        ul.scrollTop = from;
    }, duration)

}

function init() {
    setInterval(moveTo, 1000);
}

init();